#import "ALAttachmentElementImageView.h"
#import "SMRPopoverWindow.h"


#pragma mark Constants


#pragma mark -
#pragma mark Class Globals


#pragma mark -
@interface ALAttachmentElementImageView (ALAttachmentElementImageViewPrivateMethods)

@end


#pragma mark -
@implementation ALAttachmentElementImageView

@synthesize attachmentPopoverContentView;
@synthesize attachmentPopover;


-(BOOL)becomeFirstResponder {
	NSRect imageViewRect = [self bounds];
	imageViewRect.size.width = 0;
	[[self attachmentPopover] presentPopoverFromRect:imageViewRect inView:self permittedArrowDirections:SMRPopoverArrowDirectionAny animated:YES];
	return [super becomeFirstResponder];
}

-(BOOL)resignFirstResponder {
	[[self attachmentPopover] dismissPopoverAnimated:YES];
	return [super resignFirstResponder];
}

-(void)viewDidMoveToWindow {
	if (![self attachmentPopoverContentView] || [self attachmentPopover])
		return;
	[self setAttachmentPopover:[[SMRPopoverWindow alloc] initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]];
	[[self attachmentPopover] setContentView:[self attachmentPopoverContentView]];
	[[self attachmentPopover] setShouldBecomeKey:NO];
}

@end
